from rest_framework import serializers
from .models import UserInfo,Addr

class UserInfoSerializer(serializers.ModelSerializer):
  class Meta:
    model = UserInfo
    # 所有字段
    fields = '__all__'
class AddrSerializer(serializers.ModelSerializer):
  class Meta:
    model = Addr
    # exclude  排除掉一些字段
    # read_only_fields 字段只读
    # 指定字段
    fields = ('mobile','info')
    # extra_kwargs为原有Serializer参数修改或添加
    extra_kwargs = {
      'password':{'min_value':5,'required':True}
    }
#模型对象的__str__返回的结果
# user= StringRelatedField()
#模型对象返回的结果
# user = UserInfoSerializer()
#返回模型对象的某一个字段
# user = serializers.SlugRelatedField(read_only=True,slug_filed='name')
